// SPDX-License-Identifier: GPL-3.0-or-later

import QtQuick
import Fk
import Fk.Pages

// 父组件
Item {
  id: root
  property string skill
  property var extra_data

  // 第一个按钮
  MetroButton {
    id: button
    anchors.bottom: parent.bottom
    anchors.right: parent.right
    property var choices : (extra_data !== undefined) ? extra_data.choices : []
    property var all_choices : (extra_data !== undefined) ? extra_data.all_choices : []
    property string default_choice : (extra_data !== undefined) ? extra_data.default_choice : ""
    property string answer: default_choice

    text: Util.processPrompt(answer)

    onAnswerChanged: {
      if (!answer) return;
      lcall("UpdateRequestUI", "Interaction", "1", "update", answer+","+button2.answer);
    }

    onClicked: {
      roomScene.popupBox.sourceComponent = Qt.createComponent(AppPath + "/Fk/RoomElement/ChoiceBox.qml");
      const box = roomScene.popupBox.item;
      box.options = choices;
      box.all_options = all_choices;
      box.skill_name = skill;
      box.accepted.connect(() => {
        answer = all_choices[box.result];
      });
    }
  }

  // 第二个按钮
  MetroButton {
    id: button2
    anchors.bottom: button.bottom
    anchors.right: button.left
    anchors.rightMargin: 20
    property var choices : (extra_data !== undefined) ? extra_data.choices : []
    property var all_choices : (extra_data !== undefined) ? extra_data.all_choices : []
    property string default_choice : (extra_data !== undefined) ? extra_data.default_choice : ""
    property string answer: default_choice

    text: Util.processPrompt(answer)

    onAnswerChanged: {
      if (!answer) return;
      lcall("UpdateRequestUI", "Interaction", "1", "update", button.answer+","+answer);
    }

    onClicked: {
      roomScene.popupBox.sourceComponent = Qt.createComponent(AppPath + "/Fk/RoomElement/ChoiceBox.qml");
      const box = roomScene.popupBox.item;
      box.options = choices;
      box.all_options = all_choices;
      box.skill_name = skill;
      box.accepted.connect(() => {
        answer = all_choices[box.result];
      });
    }
  }
}